package it.getta.vicinometro.adapter;

import it.getta.vicinometro.R;
import it.getta.vicinometro.resources.ResBundle;
import it.getta.vicinometro.utils.FileCache;
import it.getta.vicinometro.utils.ImageLoader;
import it.getta.vicinometro.utils.Utils;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class FullscreenLazyGalleryAdapter extends SwipeIndicatorAdapter {

	private String[] mImages;
	public ImageLoader mImageLoader; 
	private Handler mHandler = new Handler();
	private Context mContext;
	
	public FullscreenLazyGalleryAdapter(Context context, FileCache fileCache, int selectorResId) {
		super(context, selectorResId);
		mImageLoader=new ImageLoader(context, fileCache);
		mContext = context;
	}

	public FullscreenLazyGalleryAdapter(Context context, FileCache fileCache) {
		super(context);
		mImageLoader=new ImageLoader(context, fileCache);
		mContext = context;
	}

	@Override
	public int getCount() { 
		return mImages.length;
	}

	@Override
	public String getItem(int position) {
		return mImages[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		FrameLayout view = (FrameLayout) convertView;
		if (view == null) {
			view = (FrameLayout) mInflater.inflate(R.layout.fullscreen_gallery_item, null);
		}
		
		int dWidth = Utils.getDisplayWidth((Activity)mContext);
		int dHeight = Utils.getDisplayHeight((Activity)mContext);
		
		if(Utils.isLandscape((Activity)mContext)) {
//			dHeight = dHeight - (int)Utils.pxToDip(mContext, ResBundle.GALLERY_BOTTOM_SPACE);
			dHeight = dHeight - ResBundle.GALLERY_BOTTOM_SPACE;
		}
		
		FrameLayout.LayoutParams imageParams = new FrameLayout.LayoutParams(dWidth, dHeight);
		
		ImageView image = (ImageView)view.findViewById(R.id.fullscreen_item_image);
		image.setLayoutParams(imageParams);
		Utils.hardLong("FULL_IMAGE_PATH = " + getItem(position));
		mImageLoader.DisplayImage(getItem(position), image);
		return view;
	}
	
	public void setData(String[] data) {
		mImages = data;
		mHandler.post(new Runnable() {
			
			@Override
			public void run() {
				notifyDataSetChanged();
				
			}
		});
		
		
	}

}
